package org.real.guetshop.mapper;

import org.apache.ibatis.annotations.*;
import org.real.guetshop.pojo.dto.AddressDTO;
import org.real.guetshop.pojo.entity.Address;
import org.real.guetshop.pojo.vo.AddressVO;

import java.util.List;

@Mapper
public interface AddressMapper {
    /**
     * 用户添加收货地址
     * @param addressDTO
     */
    @Insert("insert into address (address, user_id,phone,consignee) values (#{address},#{userId},#{phone},#{consignee})")
    void addNewAddr(AddressDTO addressDTO);

    /**
     * 用户获取收货地址列表
     * @param userId
     * @return
     */
    @Select("select * from address where user_id = #{userId}")
    List<AddressVO> getAddrById(Integer userId);

    /**
     * 用户编辑收货地址
     * @param address
     */
//    @Update("update adress set address = #{address} where id = #{id} and user_id = #{userId}")
    void editAddr(Address address);

    /**
     * 用户设置默认地址
     * @param address
     */
    @Update("update user set address = #{address} where id = #{userId}")
    void setDefaultAddr(Address address);

    /**
     * 用户删除地址
     * @param address
     */
    @Delete("delete from address where id = #{id} and user_id = #{userId}")
    void deleteAddr(Address address);
}
